<?php
/**
 * Promote blogposts to the frontpage
 *
 * @version 0.1 
 * @license MIT License http://www.opensource.org/licenses/mit-license.php
 * @copyright (c) 2007 Geir Arne Brevik
 * @author Geir Arne Brevik
 */
include_once('lib.php'); // include bootstrapping and helper functions

$doc_title = 'Promote posts to frontpage';

include('meta.php');
include('header.php');

// get all blogposts allowed to show on the frontpage
$blogposts = MiniBlog::index(array('frontpage_allowed' => true));

if ($blogposts){
	?><table>
		<caption>Posts</caption>
		<tr>
			<th>Title (click to see)</th>
			<th>Author</th>
			<th>When?</th>
			<th>Change status</th>
		</tr>
	<?php
	foreach($blogposts as $blogpost) {
		?><tr>
		<td><a href="<?php echo($blogpost->permalink); ?>" title="<?php printf('Go to %s', $blogpost->title); ?>"><?php echo($blogpost->title); ?></a></td>
		<td><?php echo(userLink($blogpost->created_by)); ?></td>
		<td><?php echo(showDate($blogpost->created_at)); ?></td>
		<td>
			<form action="?" method="POST">
				<input type="hidden" name="where" value="miniblog">
				<input type="hidden" name="action" value="setFrontpageStatus">
				<input type="hidden" name="miniblog[id]" value="<?php echo($blogpost->id); ?>">
				<input type="hidden" name="miniblog[visible_on_frontpage]" value="<?php echo($blogpost->visible_on_frontpage == 1 ? 0 : 1); ?>">
				<input type="submit" value="<?php echo($blogpost->visible_on_frontpage == 1 ? 'Hide' : 'Show'); ?>">
			</form>
		</td>
		</tr><?php
	}
	?></table><?php
} else {
	echo('No blogposts found');
}

include('footer.php');
?>